Skip to content

Join Response.String() messages with a newline like .NET ConcatText - #742

Open
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:response-string-newline-concattext
Open

Join Response.String() messages with a newline like .NET ConcatText#742
PratikDhanave wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:response-string-newline-concattext

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Response.String() flattened the text of every message into a single strings.Builder with no separator. For a two-message assistant turn (foo, Bar) it returned fooBar. It now joins each non-empty per-message text with a newline, yielding foo\nBar, and skips empty messages so no double newline is produced. Text glued within a single message (multiple TextContent items) is unchanged.

Why (.NET parity)

In microsoft/agent-framework, AgentResponse.Text is backed by messages.ConcatText(). ConcatText(IList<ChatMessage>) documents that "A newline separator is added between each non-empty piece of text" and uses AppendLine between non-empty messages. The Go port glued messages together instead, so the same two-message turn produced fooBar in Go vs foo\nBar in .NET.

The per-message join was already correct: msg.String() == message.Contents.Text(), the analog of ChatMessage.Text. This change reuses msg.String() and only fixes the cross-message separator.

This also aligns the agent-as-tool result: agenttool's FuncTool returns resp.String() as the tool output, the analog of .NET AsAIFunction returning response.Text.

Testing

Added TestResponse_String in agent/response_test.go (black-box, package agent_test) covering: two single-text messages join with a newline; an empty middle message is skipped without a double newline; multiple TextContent items within one message stay glued. go build ./..., go vet ./agent/..., and go test ./agent/... (plus ./tool/agenttool/...) pass.

Copilot AI review requested due to automatic review settings July 24, 2026 04:00
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 04:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns agent.Response.String() output with the .NET ConcatText / AgentResponse.Text behavior by inserting a newline between each non-empty message’s text, instead of concatenating message texts with no separator.

Changes:

  • Update Response.String() to join each non-empty msg.String() with \n and skip empty messages.
  • Add black-box tests covering newline joining, skipping empty messages without double newlines, and preserving within-message text concatenation across multiple TextContent items.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agent/response.go Changes Response.String() to newline-separate non-empty message text using msg.String() (which delegates to message.Contents.Text()).
agent/response_test.go Adds TestResponse_String to validate cross-message newline joining and empty-message skipping while keeping within-message concatenation unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs labels Jul 24, 2026
@github-actions

This comment has been minimized.

Response.String() flattened every message's text into one builder with no
separator, so a multi-message assistant turn returned "fooBar" where .NET
AgentResponse.Text (backed by ChatMessage list ConcatText) returns "foo\nBar".
Join each non-empty per-message text with a newline, skipping empty messages,
matching .NET semantics. This also aligns the agent-as-tool result returned by
agenttool's FuncTool, which surfaces resp.String().
@PratikDhanave
PratikDhanave force-pushed the response-string-newline-concattext branch from a3831db to f533990 Compare July 24, 2026 09:30
@github-actions

This comment has been minimized.

@gdams
gdams added this pull request to the merge queue Jul 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jul 29, 2026
@gdams
gdams enabled auto-merge July 29, 2026 14:37
# Conflicts:
#	agent/response_test.go
auto-merge was automatically disabled August 4, 2026 05:37

Head branch was pushed to by a user without write access

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Go API Consistency Review — Parity Approved ✅

PR: Join Response.String() messages with a newline like .NET ConcatText
Changed files: agent/response.go, agent/response_test.go

Summary

This PR fixes a behavioral divergence in the exported Response.String() method. The change is a parity improvement, not a new divergence.

Upstream reference verified:

  • .NETAgentResponse.Text delegates to this._messages?.ConcatText() (in dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs). ConcatText joins non-empty messages with a newline, matching the new Go behavior exactly.
  • AgentResponse.ToString() in .NET returns this.Text, so .NET ToString() == Go Response.String() — both now produce "foo Bar" for a two-message response.
  • The per-message join (multiple TextContent items within one message concatenated without separator) is unchanged and also matches .NET ChatMessage.Text semantics.

Labels:

  • public-api-change ✅ — Correct. Response.String() is an exported method with an observable behavioral change.
  • parity-approved ✅ — Correct. The change brings Go into alignment with .NET; no divergence found.

No parity issues identified. The PR improves cross-SDK consistency.

Generated by Go API Consistency Review Agent · sonnet46 · 25.7 AIC · ⌖ 5.61 AIC · ⊞ 5.7K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants